﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using BBICMS.Model;

namespace BBICMS.Repository
{
   public class ArticleRepository  : GenericRepository<Post>, IArticleRepository
    {
        public ArticleRepository(DbContext context) : base(context) { }
        //public ArticleRepository(DbContext context)
        //    : base(context)
        //{

        //}

       public IEnumerable<Post> GetPageArticles(int PageIndex, int PageSize, int? BlogId, string Keyword, out int Count)
        {
            var query = this.DBSet.Include(p=>p.Blog).AsQueryable();
            

            if (BlogId > 0)
            {
                query = query.Where(p => p.BlogId == BlogId);
            }

            if (string.IsNullOrEmpty(Keyword))
            {
                query = query.Where(p => p.Title.Contains(Keyword));
            }

            Count = query.Count();

            return query.Skip(PageIndex).Take(PageSize).ToList();
        }
    }
}
